import Mock from "mockjs"

//生成用户模块的模拟数据机接口，public目录下存放图片
let dataList = [];

dataList.push({
	id: 1, //编号
	name: "dingding", //
	password: "123456",
	avatar: "/images/user_1.png", //图片 public目录下存放	
});

dataList.push({
	id: 2, //编号
	name: "dingding2", //
	password: "123456",
	avatar: "/images/user_2.png", //图片 public目录下存放	
});

dataList.push({
	id: 3, //编号
	name: "dingding3", //
	password: "123456",
	avatar: "/images/user_3.png", //图片 public目录下存放	
});

dataList.push({
	id: 4, //编号
	name: "dingding4", //
	password: "123456",
	avatar: "/images/user_4.png", //图片 public目录下存放	
});

// 模拟接口
Mock.mock(new RegExp('/user/login'), 'post', options => {
	console.log(options) //仅仅是为了测试，看看这个值。
	let params = JSON.parse(options.body) // POST接口通过Body传的数据
	let user = dataList.filter(item => item.name == params.name && item.password == params.password)
	if (user.length > 0) {
		user = user[0]
	} else { user = {} }
	return {
		code: user ? 1 : 0,
		msg: user ? "登录成功" : "登录失败",
		data: user ? {
			token: 'token1234567890',
			user: user,
		} : {}
	}
})

//详细用法参见官网   http://mockjs.com/